package net.airtheva.hexagonMatrix.data;

public class Plane {

	public static Plane Calculate(Vertex a, Vertex b, Vertex c) {
		
		float A = (b.Position.Data[1] - a.Position.Data[1]) * (c.Position.Data[2] - a.Position.Data[2]) - (b.Position.Data[2] - a.Position.Data[2]) * (c.Position.Data[1] - a.Position.Data[1]);
		float B = (b.Position.Data[2] - a.Position.Data[2]) * (c.Position.Data[0] - a.Position.Data[0]) - (b.Position.Data[0] - a.Position.Data[0]) * (c.Position.Data[2] - a.Position.Data[2]);
		float C = (b.Position.Data[0] - a.Position.Data[0]) * (c.Position.Data[1] - a.Position.Data[1]) - (b.Position.Data[1] - a.Position.Data[1]) * (c.Position.Data[0] - a.Position.Data[0]);
		
		Vertex point = (new Vertex()).Position(a.Position);
		Vector3f vector = new Vector3f(A, B, C);
		Plane plane = new Plane(point, vector);
		
		return plane;
		
	}
	
	public Vertex Point;
	public Vector3f Vector;
	
	public Plane(Vertex point, Vector3f vector) {
		// TODO Auto-generated constructor stub
		
		Point = (new Vertex()).Position(point.Position);
		Vector = new Vector3f(vector);
		
	}
	
	public float A() {
		
		return Vector.Data[0];
		
	}
	
	public float B() {
		
		return Vector.Data[1];
		
	}
	
	public float C() {
		
		return Vector.Data[2];
		
	}
	
	public float D() {
		
		return - (Vector.X() * Point.Position.X() + Vector.Y() * Point.Position.Y() + Vector.Z() * Point.Position.Z());
		
	}
	
}
